package com.example.demo.service;

import com.example.demo.mapper.LogMapper;
import com.example.demo.mapper.UserMapper;
import com.example.demo.model.LogInfo;
import com.example.demo.model.UserInfo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * Creat with IntelliJ IDEA
 * Description:
 * User:WZW
 * Date:2022-08-28
 * Time:17:31
 */
@Service
public class UserService {
    @Resource
    private UserMapper userMapper;

    @Resource
    private LogMapper logMapper;

    @Transactional(propagation = Propagation.REQUIRES_NEW)
    public int add(UserInfo userInfo) {
        int result = userMapper.add(userInfo);
        // 通常日志在这里添加
//        LogInfo logInfo = new LogInfo();
//        logInfo.setName("添加用户");
//        logInfo.setDesc("添加用户结果：" + result);
//        int logResult = logMapper.add(logInfo);
        return result;
    }

}
